Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
buffer-alloc
Advanced tools
Package description
The buffer-alloc package is a utility for allocating buffer memory in Node.js. It provides a way to create a buffer of a specified size filled with zeros or another specified value. This is particularly useful in scenarios where you need to ensure that newly allocated memory does not contain old or sensitive data. It mimics the Buffer.alloc method introduced in Node.js v5.10.0, offering a polyfill for older versions of Node.js or an alternative method for newer versions.
Allocating a buffer filled with zeros
This feature allows for the creation of a new buffer of a specified size, with each byte initialized to zero. It's useful for when you need a clean buffer with no pre-existing data.
const bufferAlloc = require('buffer-alloc');
const buffer = bufferAlloc(10); // creates a 10-byte buffer filled with zeros
Allocating a buffer filled with a specific value
This feature enables the creation of a buffer where each byte is initialized to a specific value provided by the user. This can be useful for initializing a buffer to a non-zero state for specific use cases.
const bufferAlloc = require('buffer-alloc');
const buffer = bufferAlloc(10, 0x1); // creates a 10-byte buffer filled with 0x1
Similar to buffer-alloc, buffer-from is designed to create a new Buffer instance from a variety of inputs (e.g., arrays, strings, or another buffer). While buffer-alloc focuses on allocating new memory, buffer-from provides more flexibility in creating buffers from existing data.
The safe-buffer package offers a safer version of the Node.js Buffer API, addressing security and usability concerns. It includes methods similar to buffer-alloc for creating buffers but adds additional checks and features to prevent common issues with buffer management in Node.js.
Readme
A ponyfill for Buffer.alloc
.
Works as Node.js: v7.0.0
Works on Node.js: v0.10.0
npm install --save buffer-alloc
const alloc = require('buffer-alloc')
console.log(alloc(4))
//=> <Buffer 00 00 00 00>
console.log(alloc(6, 0x41))
//=> <Buffer 41 41 41 41 41 41>
console.log(alloc(10, 'linus', 'utf8'))
//=> <Buffer 6c 69 6e 75 73 6c 69 6e 75 73>
size
<Integer> The desired length of the new Buffer
fill
<String> | <Buffer> | <Integer> A value to pre-fill the new Buffer
with. Default: 0
encoding
<String> If fill
is a string, this is its encoding. Default: 'utf8'
Allocates a new Buffer
of size
bytes. If fill
is undefined
, the Buffer
will be zero-filled.
Buffer.allocUnsafe
Buffer.fill
Buffer.from
FAQs
A [ponyfill](https://ponyfill.com) for `Buffer.alloc`.
The npm package buffer-alloc receives a total of 4,243,500 weekly downloads. As such, buffer-alloc popularity was classified as popular.
We found that buffer-alloc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.